//% color="#4169E1" iconWidth=50 iconHeight=40
namespace DFRobot_HX711_I2C{
    //% block="Initialize the weight sensor until successful, address [ADDR] " blockType="command" 
    //% ADDR.shadow="dropdown" ADDR.options="ADDR"
    export function DFRobot_HX711_I2CInit(parameter: any, block: any) {
        let addr = parameter.ADDR.code;
    
        Generator.addImport("from DFRobot_HX711_I2C import *");
        Generator.addCode(`hx711 = DFRobot_HX711_I2C(${addr})`);
        Generator.addCode(`while(hx711.begin()==0):
    print("Init faild!!")`);
       
        
    }
    //% block="Set the calibration value [NUMBER]" blockType="command"
    //% NUMBER.shadow="number" NUMBER.defl="100"
    export function DFRobot_HX711_I2CSetCalWeight(parameter: any, block: any) { 
        let number=parameter.NUMBER.code;
        Generator.addCode(`hx711.set_calibration(${number})`);
     
   
   }
    //% block="Set the sensor auto-calibration trigger threshold [NUMBER1]" blockType="command"
    //% NUMBER1.shadow="number" NUMBER1.defl="30"
    export function DFRobot_HX711_I2CSetThreshold(parameter: any, block: any) { 
      let number1=parameter.NUMBER1.code;
      Generator.addCode(`hx711.set_threshold(${number1})`);
   
 
 }
//     //% block="DFRobot_HX711_I2C  enableCal  " blockType="command"
     
//     export function DFRobot_HX711_I2CEnableCal(parameter: any, block: any) { 
        

//         Generator.addCode(`hx711.enable_cal()`);
   
//    }
//         //% block="DFRobot_HX711_I2CGetCalFlag" blockType="boolean" 
//   export function DFRobot_HX711_I2CGetCalFlag(parameter: any, block: any) { 
//     Generator.addCode( `hx711.get_cal_flag()`);

// }
//    /*  //% block="DFRobot_HX711_I2C  peel  " blockType="command"
     
//      export function DFRobot_HX711_I2CPeel(parameter: any, block: any) { 
        

//         Generator.addSetup(`DFRobot_HX711_I2CInit5`,`MyScale.peel();`);
   
//    }*/
//      //% block="DFRobot_HX711_I2CSetCalibration  " blockType="command" 
     
//   export function DFRobot_HX711_I2CSetCalibration(parameter: any, block: any) { 
      
        
//     Generator.addCode(`hx711.set_calibration(hx711.get_calibration())`);

// }

   //% block="Obtain weight" blockType="reporter" 
   export function DFRobot_HX711_I2CReadWeight(parameter: any, block: any) { 

    Generator.addCode( [`hx711.read_weight(10)`,Generator.ORDER_UNARY_POSTFIX]);

}

//   //% block="---"
//   export function noteSep() {

//   }
//        //% block="DFRobot_HX711_I2CgetCalibration  " blockType="reporter" 
 
//        export function DFRobot_HX711_I2CGetCalibration(parameter: any, block: any) { 
      
        
//         Generator.addCode(`hx711.get_calibration()`);
   
//    }
//     //% block="DFRobot_HX711_I2CSetCalibration [NUMBER2]" blockType="command" 
//     //% NUMBER2.shadow="number" NUMBER2.defl="2000"
     
//     export function DFRobot_HX711_I2CSetCalibration1(parameter: any, block: any) { 
//       let number2=parameter.NUMBER2.code;
        
//         Generator.addCode(`hx711.set_calibration(${number2})`);
   
//    }


}